function get_xhr(){
	var xhr;
    if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    return xhr;
}

function refresh_serv(server){
	var xhr;
    xhr = get_xhr();
    xhr.onreadystatechange = function() { 
        if(xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
        	location.reload();
        }
    }

    //on appelle le ping
    xhr.open("GET", "./index.php?update=ok&server="+server, true);
    xhr.send(null);
}

function refresh_list_server(typed,server){
	window.opener.document.location.href = "index.php?page="+typed+"&server="+server;
}

first = 0;
function vide(name){
	var box=document.getElementsByName(name);
	if ((box[0].value=="search")&&(first==0)){
		box[0].value="";
		first =1;
	}
}


function ajax_multiping(arrayaddress){
	for (var i = 0; i < arrayaddress.length; i++){
		ajax_ping(arrayaddress[i]);
		setInterval("ajax_ping('"+arrayaddress[i]+"');",3000);
	  }	
}

function ajax_ping(address){
	var xhr;
    xhr = get_xhr();
    //on définit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() { alert_ajax(xhr,address); };
        
    //on appelle le ping
    xhr.open("GET", "./index.php?ping="+address, true);
    xhr.send(null);
}

function alert_ajax(xhr,address){
	  if (xhr.readyState==4){
		  var castr;
		  var ping;
		  castr = document.getElementById(address);
		  ping = xhr.responseText;
		  //alert(ping);
		  if (ping == "-1"){
			  castr.innerHTML = "Down";
		  }
		  else{
			  castr.innerHTML = ping;
		  }

	  }
}